﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PuzzleDiamonds
{
    public class SoundManager
    {
        static SoundManager m_instance = null;
        Collection<MediaElement> m_soundList = new Collection<MediaElement>();

        protected SoundManager()
        {

        }

        public static SoundManager Instance()
        {
            if (m_instance == null)
                m_instance = new SoundManager();
            return m_instance;
        }

        public void AddMediaElement(MediaElement pMediaElement)
        {
            m_soundList.Add(pMediaElement);
        }

        public MediaElement GetMediaElement(String pName)
        {
            foreach (MediaElement me in m_soundList)
            {
                if (me.Name == pName)
                    return me;
            }
            return null;
        }

        public void PlaySound(String pName)
        {
            MediaElement me = GetMediaElement(pName);

            if (me != null)
            {
                me.Position = TimeSpan.Zero;
                me.Play();
            }
        }
    }
}
